import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.*;


public class Choose extends JFrame implements ActionListener{
	String choice;
    ButtonGroup group;
    JButton selection;
    JRadioButton personButton;  
    JRadioButton studentButton; 
    JRadioButton employeeButton;
    JRadioButton exitButton; 
	public Choose()
	{
		setLayout(new GridLayout(5, 2, 5, 5));
	    JRadioButton personButton = new JRadioButton("Person");
	    personButton.setMnemonic(KeyEvent.VK_B);
	    personButton.setActionCommand("PERSON");
	    personButton.setSelected(true);

	    JRadioButton studentButton = new JRadioButton("Student");
	    studentButton.setMnemonic(KeyEvent.VK_C);
	    studentButton.setActionCommand("STUDENT");

	    JRadioButton employeeButton = new JRadioButton("Employee");
	    employeeButton.setMnemonic(KeyEvent.VK_D);
	    employeeButton.setActionCommand("EMPLOYEE");

	    JRadioButton exitButton = new JRadioButton("Exit");
	    exitButton.setMnemonic(KeyEvent.VK_R);
	    exitButton.setActionCommand("EXIT");

	    //Group the radio buttons.
	    group = new ButtonGroup();
	    group.add(personButton);
	    group.add(studentButton);
	    group.add(employeeButton);
	    group.add(exitButton);

	    //Register a listener for the radio buttons.
	    personButton.addActionListener(this);
	    studentButton.addActionListener(this);
	    employeeButton.addActionListener(this);
	    exitButton.addActionListener(this);
	    
	    selection=new JButton("Selection");
		selection.setActionCommand("SELECTED");
	    selection.addActionListener(this);
	    add(personButton);
	    add(studentButton);
	    add(employeeButton);
	    add(exitButton);
	    add(selection);
	}
	public void initialize()
	{
		this.setTitle("Choose");
		this.setSize(400,300);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent event)
	{
		String command=event.getActionCommand();
		if(command=="SELECTED")
		{
			if(personButton.isSelected()==true)
			{
				Person p1=new Person();
				p1.initialize();
			}
			else if(studentButton.isSelected()==true)
			{
				Student s1=new Student();
				s1.initialize();
			}
			else if(employeeButton.isSelected()==true)
			{
				Employee e1=new Employee();
				e1.initialize();
			}
			else dispose();
		}
	}
}
